package com.szxy.service.impl;

import com.szxy.service.feign.OrderServiceFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * @Author: zwz
 * @Date:2020/7/15 22:41
 * @Description:com.szxy.service.impl
 * @Version:1.0
 **/
@Service
public class OrderServiceApi {

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private OrderServiceFeign orderServiceFeign;

    /**
     * 记录日志
     */
    private static final Logger logger = LoggerFactory.getLogger(OrderServiceApi.class);


    /**
     * 下订单
     */
    public void create(String userId, String productId, int count) {
//        ResponseEntity<Void> restTemplateForEntity = this.restTemplate.getForEntity(
//                "http://order-service/addOrder/{userId}/{productId}/{count}",
//                Void.class,
//                userId,
//                productId,
//                count
//        );
        ResponseEntity<Void> restTemplateForEntity = this.orderServiceFeign.create(userId, productId, count);
        if (restTemplateForEntity.getStatusCode() == HttpStatus.OK) {
            logger.info("远程调用 order 服务成功!");
            return;
        }
        throw new RuntimeException("远程调用 order 服务失败...");
    }
}
